package com.cxc.simple;

import org.omg.CORBA.PUBLIC_MEMBER;

import java.sql.SQLOutput;
import java.util.concurrent.locks.LockSupport;

public class PrintThreadState {

    /**
     * <hr>
     *     NEW
     * </hr>
     */
    public static void newState(){
        System.out.println(new Thread().getState());
    }
    public static void runnableState(){
        Thread t = new Thread(()->{
            while (true){

            }
        });
        t.start();
        System.out.println(t.getState());
    }

    public static void blockedState() throws InterruptedException {
        Object monitor = new Object();
        Thread thread1 = new Thread(()->{

            synchronized (monitor){
                try{
                    Thread.sleep(Integer.MAX_VALUE);
                }catch (InterruptedException e){

                }
            }
        });

        Thread  thread2 = new Thread(()->{

            synchronized (monitor){

            }
        });

        thread1.start();
        Thread.sleep(100);
        thread2.start();
        Thread.sleep(100);
        System.out.println(thread2.getState());
    }

    public static void waitState() throws InterruptedException {

        Thread thread = new Thread(()->{
            LockSupport.park();
            while (true){

            }
        });
        thread.start();
        Thread.sleep(100);
        System.out.println(thread.getState());
        LockSupport.unpark(thread);
        Thread.sleep(100);
        System.out.println(thread.getState());

}

public static void timedWaitState() throws InterruptedException {

    Thread thread = new Thread(() -> {

    });
    Thread.sleep(100);
    System.out.println(thread.getState());

}

    public static void main(String[] args) throws InterruptedException {
//        newState();
//        runnableState();
//        blockedState();
        waitState();
    }





}
